/*
 * yangbo
 */
(function(window) {
	window.Tyre = {};

	Tyre.define = function(name, context, definition) {
		context[name] = definition;
	};
	
	Tyre.cookie = {
		g: function(k) {
			return "" || (new RegExp(["(?:; )?", k, "=([^;]*);?"].join(""))).test(document.cookie) && RegExp["$1"];
		},
		s: function(k, v, e, p, d) {
			document.cookie = [k, "=", v, e && e["toGMTString"] ? ';expires=' + e.toGMTString() : "", ";path=" + (p && p != null && p != '' ? p: "/") + (d && d != null && d != "" ? ";domain=" + d: "")].join("");
		}
	};

    Tyre.browser = {
        PMP_SUPPORTED_IE_VERSION: "9.0",
        SUPPORTED: true,
        validate : function() {
            try {
                var d = window;
                var l = function $a(a, b) {
                    return a < b ? -1 : a > b ? 1 : 0
                };
                var m;
                e:{
                    var p = d.navigator;
                    if (p) {
                        var r = p.userAgent;
                        if (r) {
                            m = r;
                            break e
                        }
                    }
                    m = ""
                }
                var s = function $b(a) {
                    return-1 != m.indexOf(a)
                };
                var t = s("Opera") || s("OPR"), u = s("Trident") || s("MSIE"), v = s("Gecko") && -1 == m.toLowerCase().indexOf("webkit") && !(s("Trident") || s("MSIE")), w = -1 != m.toLowerCase().indexOf("webkit"), x = function () {
                    var e = "", a;
                    if (t && d.opera)return e =
                        d.opera.version, "function" == f(e) ? e() : e;
                    v ? a = /rv\:([^\);]+)(\)|;)/ : u ? a = /\b(?:MSIE|rv)[: ]([^\);]+)(\)|;)/ : w && (a = /WebKit\/(\S+)/);
                    a && (e = (e = a.exec(m)) ? e[1] : "");
                    return u && (a = (a = d.document) ? a.documentMode : void 0, a > parseFloat(e)) ? String(a) : e
                }(), y = {}, z = function $c(a) {
                    var b;
                    if (!(b = y[a])) {
                        b = 0;
                        for (var c = String(x).replace(/^[\s\xa0]+|[\s\xa0]+$/g, "").split("."), q = String(a).replace(/^[\s\xa0]+|[\s\xa0]+$/g, "").split("."), A = Math.max(c.length, q.length), n = 0; 0 == b && n < A; n++) {
                            var B = c[n] || "", C = q[n] || "", D = RegExp("(\\d*)(\\D*)",
                                "g"), E = RegExp("(\\d*)(\\D*)", "g");
                            do {
                                var h = D.exec(B) || ["", "", ""], k = E.exec(C) || ["", "", ""];
                                if (0 == h[0].length && 0 == k[0].length)break;
                                b = l(0 == h[1].length ? 0 : parseInt(h[1], 10), 0 == k[1].length ? 0 : parseInt(k[1], 10)) || l(0 == h[2].length, 0 == k[2].length) || l(h[2], k[2])
                            } while (0 == b)
                        }
                        b = y[a] = 0 <= b
                    }
                    return b
                };
                var a = (a = this.PMP_SUPPORTED_IE_VERSION, a = u && z(a) || w && z("522") || t && z("9.5") || v && z("7.0"));
                if(!a) {
                   this.SUPPORTED = false
                   $(function(){
                       var d = $("<div style=\"width:100%;height:50px;background:#f1f1f1;z-index:999999;color:#333;font-weight:bold\"></div>")
                       var c = $("<div style=\"min-width:1200px;margin:auto;line-height:50px;margin-left:20px;\"></div>");
                       c.html("你的浏览器版本过低，无法展示某些功能，建议升级浏览器以获取更好的体验。") // （目前支持IE9+，Chrome27+，Firefox7+，Safari5+，Opera9.5+）
                       d.append(c)
                       d.insertBefore($(".website"))
                   })
                }
            } catch (e) {

            }
        }
    }
	// ////////////////////////////////////////////////////
	Tyre.include = function(file) {
		var includePath = '';
		var files = typeof file == "string" ? [file] : file;
		for (var i = 0; i < files.length; i++) {
			var name = files[i].replace(/^\s|\s$/g, "");
			var att = name.split('.');
			var ext = att[att.length - 1].toLowerCase();
			var isCSS = ext == "css";
			var tag = isCSS ? "link": "script";
			var attr = isCSS ? " type='text/css' rel='stylesheet' ": " language='javascript' type='text/javascript' ";
			var link = (isCSS ? "href": "src") + "='" + includePath + name + "'";
			if ($(tag + "[" + link + "]").length == 0) document.write("<" + tag + attr + link + "></" + tag + ">");
		}
	};
	Tyre.expend = {

		aria: 0,
		key: "P2EXID",
		
		urlnamespace:function(requestURI) {
			var l = Tyre.navtab.urlnamespace(requestURI);
			l=l.replace("/leader/","1");
			l=l.replace("/admin/","2");
			return l;
		}, 
		memory: function(e, isHide) {
			var date = new Date();
			date.setTime(date.getTime() + 90 * 24 * 3600 * 1000);
			var value = "";
			var cook = Tyre.cookie.g(this.key);
			var aria = e.attr('aria');
			var K = this.urlnamespace(requestURI) + ":" + aria + ",";
			if (cook && cook != '') {
				if (!isHide) {
					value = cook.replace(K, "");
				} else {
					if (cook.indexOf(K) == -1) value = cook + K;
					else value = cook;
				}
			} else {
				if (isHide) value = K;
			}
			try {
				Tyre.cookie.s(this.key, value, date, "", "");
			} catch(e) {
				Tyre.console.error(e);
			}

		},
		show: function(e, c) {
			var L = e;

			var unexpend = e.attr('unexpend');
			if (unexpend) return;
			var hide = e.attr('hide');
			var isHide = hide ? hide == 'true': false;

			if (c) {
				isHide = !isHide;
			} else {
				var aria = e.attr('aria');
				var cook = Tyre.cookie.g(this.key);
				var K = this.urlnamespace(requestURI) + ":" + aria + ",";
				if (cook && cook.indexOf(K) != -1) {
					isHide = true;
				}
			}

			if (isHide) {
				e.next(".box-content").hide();
				e.attr('hide', 'true');
				e.addClass('Lhd');
				var h4 = L.find('.h4');
				h4.find('.icon-j').remove();
				h4.append('<i class="icon-j icon-j-down"></i>');
				Tyre.scroll.position();
				this.memory(e, isHide);
			} else {
				e.next(".box-content").show();
				e.removeAttr('hide');
				e.removeClass('Lhd');
				var h4 = L.find('.h4');
				h4.find('.icon-j').remove();
				h4.append('<i class="icon-j icon-j-up"></i>');
				Tyre.scroll.position();
				this.memory(e, isHide);
			}
		},
		bind: function(e) {
			var that = this;
			var el = e;
			if (!el) {
				el = $('.box-header');
			}
			el.each(function() {
				var element = $(this);
				var unexpend = element.attr('unexpend');
				if (unexpend) return;
				element.attr('aria', that.aria++);
				element.find('.left').eq(0).css('cursor', 'pointer').bind('click',
				function() {
					that.show(element, '~');
				});
				that.show(element);

			});

		}
	};

	Tyre.navtab = {
		urlnamespace: function(href, size) {
            if(!href) return "";
            var l=href.indexOf("?");
            if(l!=-1){
                href=href.substring(0, l);
            }
			var c, b = 0,
			o = 0,
			l = href.length;
			if(!size) {
				size = 2;
			}
			if(size == -1) {
				size = 20000;
			}
			while (++b < l) {
				c = href.charAt(b);
				if (c == '/') {
					o++;
					if (o == size) {
						break;
					}
				}
			}
			return href.substring(0, b);
		},
		select: function() {
			this.active();
		},
		active: function() {
			var that = this;
			if (requestURI) {
				
				//var zero=null;
				//var actived = false;
				
				$('.nav-tabs .nav-tabs-hover').each(function(i) {
					var t = $(this); if(i==0) zero = t;
					var menu = t.parent().find('.dropdown-menu');
					var requestUriNamespace = that.urlnamespace(requestURI,-1);
					if(requestUriNamespace.charAt(requestUriNamespace.length-1) == "/") {
						requestUriNamespace=requestUriNamespace.substring(0, requestUriNamespace.length-1);
					}
					var href = t.attr('href');
					var hrefNamespace = that.urlnamespace(href,-1);
					 
					if (menu.size() > 0) {
						menu.find('a').each(function() {
							var href = $(this).attr('href');
							var hrefNamespace = that.urlnamespace(href,-1);
							if (requestUriNamespace == hrefNamespace) {
								$(this)
									.css("border-left","2px solid #dc483a")
									.css("font-weight", "bold")
									.css("color","#333");
								t.parent().addClass('active');
								actived=true;
								return;
							}
						});
					} else if (requestUriNamespace == hrefNamespace || (requestUriNamespace + "/") == hrefNamespace) {
						t.parent().addClass('active');
						actived=true;
					} else {
						
					}
				});
				
				// special
				//if(zero && !actived) {
				//	zero.parent().addClass('active');
				//}
				
			}
		},
		hover:function() {
			
			$(".dropdownhover").on("mouseleave",function() {
				var E = $(this);
				var L = E.find(".dropdown-menu");
				if(E.hasClass("open") && !L.attr("active")) {
					E.removeClass("open");
				}
			}).on("mouseenter",function() {
				var E = $(this);
				if(!E.hasClass("open")) {
					E.addClass("open");
				}
			});
			
			$(".dropdownhover").find(".dropdown-toggle")
				.on("click.dropdown.data-api", function(e) {
				e.stopPropagation();
			}).attr("href", "javascript:;");
		}
	};

	Tyre.loading = {
		loaders: new Array(),
		target: null,
		defaults: {
			back: true
		},
		// backcolor
		show: function(options) {
			var key = 'root';
			if (options.target) {
				var j = options.target.substring(0, 1);
				if (j == '.') {
					key = 'class_' + options.target.substring(1);
				} else if (j == '#') {
					key = 'id_' + options.target.substring(1);
				}
			}
			options = $.extend({},
			this.defaults, {},
			options);
			this.loaders[key] = $('<div id="loader_' + key + '" class="loading">加载中,请稍候...</div>');
			var load = this.loaders[key];
			if (options.target) {
				var target = $(options.target);
				load.css('position', 'relative').css('float', 'left').css('margin-top', -target.height() / 2 - 18 + 'px').css('z-index', '1000').css('top', '0');
				target.append(load);
			} else {
				$(document.body).append(load);
			}
			load.show();
			if (options.back) {
				load.attr('showbg', 'true');
				if (options.target) {
					load.attr('bgtarget', options.target);
				}
				Tyre.back.show({
					color: options.bgcolor ? options.bgcolor: undefined,
					clickhide: false,
					target: options.target
				});
			}
		},
		hide: function(bgtarget) {
			if (bgtarget) {
				var j = bgtarget.substring(0, 1);
				if (j == '.') {
					key = 'class_' + bgtarget.substring(1);
				} else if (j == '#') {
					key = 'id_' + bgtarget.substring(1);
				} else {
					key = 'root';
				}
			} else {
				key = 'root';
			}
			var load = $('#loader_' + key);
			load.remove();
			if (load.attr('showbg')) {
				if (load.attr('bgtarget')) {
					Tyre.back.hide(load.attr('bgtarget'));
				} else {
					Tyre.back.hide();
				}
			}
			this.loaders[key] = null;
		}
	};

	//Tyre.alert = function(options) {
	//
	//	if(!options) {
	//		options={};
	//	} else {
	//		if(typeof(options) == "string") {
	//			var text = options;
	//			options = {text:text};
	//		}
	//	}
	//
	//	var defaults = {
	//		text: ""
	//	};
	//	options = $.extend({},
	//	defaults, {},
	//	options);
	//	if (options.callback) {
	//
	//		if(Tyre.humane.notifyElement)
	//			Tyre.humane.notifyElement.remove();
	//
	//		Tyre.humane.notifyElement = Tyre.humane.create({
	//			timeout: 4000,
	//			baseCls: 'humane-jackedup'
	//		});
	//		Tyre.humane.notifyElement.log(options.text);
	//		//humane(options.text, options.callback)
	//	} else {
	//		if(Tyre.humane.notifyElement)
	//			Tyre.humane.notifyElement.remove();
	//		Tyre.humane.notifyElement = Tyre.humane.create({
	//			timeout: 4000,
	//			baseCls: 'humane-jackedup'
	//		});
	//		Tyre.humane.notifyElement.log(options.text);
	//	}
    //
	//};

	Tyre.ajax = function(options) {
		var defaults = {
			timeout: 30000,
			loading: true,
			alert: false
		};
		options = $.extend({},
		defaults, {},
		options);
		if (options.loading) {
			Tyre.loading.show({
				bgcolor: options.bgcolor,
				target: options.bgtarget
			});
		}
		if(options.url.split("?").length > 1){
			options.url += "&" +  Math.random();
		}else{
			options.url += "?" +  Math.random();
		}
		var complete = options.complete;
		var error = options.error;
		var success = options.success;
		options.complete = function(jqXHR, textStatus) {
			if (complete) {
				try {
					complete(jqXHR, textStatus);
				} catch(e) {
					Tyre.console.error(e);
				}
			}
			if (options.loading) {
				Tyre.loading.hide(options.bgtarget);
			}
		};
		options.error = function(jqXHR, textStatus, errorThrown) {
			if (error) {
				try {
					error(jqXHR, textStatus, errorThrown, 'error, url:' + options.url);
				} catch(e) {
					Tyre.console.error(e);
				}
			} else {
				if (jqXHR.readyState == 4){
					layer.open({
						content:'网络错误',
						time:2500
					});
				}
			}
		};
		options.success = function(data, textStatus, jqXHR) {
			if (success) {
				var response = data;
				try {
					if (typeof(response) != 'object') {
						response = jQuery.parseJSON(data);
					}
					if (response.tyreJavascriptResolver) { // 判断code字段是否存在
						if (options.alert && options.alert == true) {
							var text = (response.tip == null || response.tip == "") ? response.error == 0 ? "操作成功。": "操作失败。": response.tip;
							Tyre.alert({
								text: text
							});
						}
					} else {
						response = data;
					}
				} catch(e) {
					response = data;
					//Tyre.console.error("get response error. " + e);
				}
				try {
					success(response, textStatus, jqXHR);
				} catch(e) {
					Tyre.console.error(e);
				}
			}
		};
		$.ajax(options);
	};
	Tyre.post = function(options) {
		var defaults = {
			url: '',
			loading: true,
			alert: false,
			data: {}
		};
		options = $.extend({},
		defaults, {},
		options);
		if (options.loading) {
			Tyre.loading.show({
				bgcolor: options.bgcolor,
				target: options.bgtarget
			});
		}

		// url,data,success,dataType
		$.post(options.url, options.data, options.callback, options.dataType).success(function(data, textStatus, jqXHR) {
			if (options.success) {
				var response = data;
				try {
					if (typeof(response) != 'object') {
						response = jQuery.parseJSON(data);
					}
					if (response.tyreJavascriptResolver) { // 判断code字段是否存在
						if (options.alert && options.alert == true) {
							var text = (response.tip == null || response.tip == "") ? response.error == 0 ? "操作成功。": "操作失败。": response.tip;
							Tyre.alert({
								text: text
							});
						}
					} else {
						response = data;
					}
				} catch(e) {
					response = data;
					//Tyre.console.error("get response error" + e);
				}
				try {
					options.success(response, textStatus, jqXHR);
				} catch(e) {
					Tyre.console.error(e);
				}
			}
		}).error(function(jqXHR, textStatus, errorThrown) {
			if (options.error) {
				try {
					options.error(jqXHR, textStatus, errorThrown, 'error, url:' + options.url);
				} catch(e) {
					Tyre.console.error(e);
				}
			} else {
				if (jqXHR.readyState == 4) Tyre.alert({
					text: "网络错误"
				});
			}
		}).complete(function(jqXHR, textStatus) {
			if (options.complete) {
				try {
					options.complete(jqXHR, textStatus);
				} catch(e) {
					Tyre.console.error(e);
				}
			}
			if (options.loading) Tyre.loading.hide(options.bgtarget);
		});
	};
	// ////////////////////////////////////////////////////
	Tyre.open = function(options) {

		if (!this.winid) {
			this.winid = 0;
		}

		var features = 'top=';
		features += options.top ? options.top: 0;
		features += ',left=';
		features += options.left ? options.left: 0;
		features += ',height=';
		features += options.height ? options.height: 500;
		features += ',width=';
		features += options.width ? options.width: 500;
		features += ',toolbar=';
		features += options.toolbar ? options.toolbar: 'yes';
		features += ',titlebar=';
		features += options.titlebar ? options.titlebar: 'yes';
		features += ',status=';
		features += options.status ? options.status: 'yes';
		features += ',scrollbars=';
		features += options.scrollbars ? options.scrollbars: 'yes';
		features += ',resizable=';
		features += options.resizable ? options.resizable: 'yes';
		features += ',menubar=';
		features += options.menubar ? options.menubar: 'no';
		features += ',location=';
		features += options.location ? options.location: 'yes';
		features += ',fullscreen=';
		features += options.fullscreen ? options.fullscreen: 'no';
		features += ',directories=';
		features += options.directories ? options.directories: 'yes';
		features += ',channelmode=';
		features += options.channelmode ? options.channelmode: 'no';

		Tyre.console.debug("window.open features: " + features);

		return window.open(options.url ? options.url: '', options.name ? options.name: '_win_' + this.winid, features);
	};
	// /////////////////////////////////////////////////////////
	Tyre.search = {

		mouseenter: false,
		closed: true,
		id: '__w_search',
		binded: false,
		down: function() {
			if (this.binded) {
				this.oldsearchtrigger = $('.wsearch-button');
				var search = $('<li class="tabs-search" search-label="请输入(项目名称, 人名)" style="float:right"><a href="javascript:;">&nbsp;<i class="icon-search"></i>&nbsp;</a></li>');
				$('.wnavbar').find('.nav-tabs').append(search);
				this.bind(search, true);
				this.fixed = true;
				this.trigger = search;
				this.resize();
			}
		},
		up: function() {
			if (this.binded) {
				$('.wnavbar').find('.nav-tabs').find('.tabs-search').remove();
				this.fixed = false;
				if (this.oldsearchtrigger) Tyre.search.trigger = this.oldsearchtrigger;
				else Tyre.search.trigger = $('.wsearch-button');
				this.resize();
			}
		},
		position: function() {

			var div = $('#' + this.id);
			var off = this.trigger.offset();

			div.css('left', off.left + this.trigger.width() - 500 + "px");

			if (this.fixed) {
				div.css('position', 'fixed');
				div.css('top', off.top + this.trigger.height() - $(window).scrollTop() + "px");
			} else {
				div.css('position', 'absolute');
				div.css('top', off.top + this.trigger.height() + "px");
			}
		},
		show: function(trigger, fixed) {

			this.hide();

			this.trigger = trigger;
			this.fixed = fixed;

			var label = trigger.attr('search-label');
			var div = $('<div id="' + this.id + '" class="wsearch"></div>');
			$(document.body).append(div);

			this.position();

			div.html('<input type="text" name="s" class="sinput" placeholder="' + (label ? label: '') + '" autofocus x-webkit-speech><button type="submit" class="sbtn"><i class="icon-search icon-white"></i></button>');

			var that = this;
			// .on('click.xxx', '.zzz form', function (e) { e.stopPropagation() })
			$(document).on('click.wsearch',
			function(e) {
				that.hide(e);
			});
			$(window).on('resize.wsearch',
			function() {
				that.resize();
			});

			this.closed = false;

		},
		resize: function() {
			if (!this.closed) {
				this.position();
			}

		},
		hide: function(e) {
			if (e) {
				if ($(e.target).closest('#' + this.id).length > 0 || $(e.target).closest(this.trigger).length > 0 || ($(e.target)[0] == this.trigger[0])) {
					return
				}
			}
			$(document).off('click.wsearch');
			$(window).off('resize.wsearch');
			$('#' + this.id).remove();
			this.closed = true;

		},
		bind: function(trigger, fixed) {
			if (!trigger) {
				trigger = $('.wsearch-button');
			}
			var that = this;
			trigger.bind('click',
			function() {
				that.show($(this), fixed);
			});
			this.binded = true;
		}

	};

	// ////////////////////////////////////////////////////
	Tyre.scroll = {
		fn: {
			up: [],
			down: []
		},
		status: {
			up: true
		},
		target: null,
		navbar: '.wnavbar',
		navbarClass: 'navbar-fixed-top-l',
		topbar: '.navbar',
		content: '.nav-content-div',
		contentClass: 'nav-ls',
		on: function(k, fn) {
			if (k == 'up') this.fn.up[this.fn.up.length] = fn;
			else if (k == 'down') this.fn.down[this.fn.down.length] = fn;
		},
		position: function() {
            if(!Tyre.browser.SUPPORTED) {
                return;
            }
			var that = this;
			var top = $(window).scrollTop();
			var change = false;

			if (top >= 48) {
				if (that.status.up) {
					that.status.up = false;
					change = true;
				}
			} else if (top <= 48) {
				if (!that.status.up) {
					that.status.up = true;
					change = true;
				}
			}
			// var t = 0;
			// if(top<0) t=58
			// else {t=58-top;if(t<0) t=0}
			// that.target.css('top',t+'px')
			// Tyre.console.error(top+"/"+t)
			if (change) {
				if (!that.status.up) {
					that.target.addClass(that.navbarClass);
					//that.target.find(".nav-tabs").css("top","46px").animate({top:"0px"}, 350);
					$(that.content).addClass(that.contentClass);
					for (k in that.fn.down) {
						that.fn.down[k]();
					}
					Tyre.search.down();
					Tyre.console.debug("scroll down");
				} else {
					that.target.removeClass(that.navbarClass);
					$(that.content).removeClass(that.contentClass);
					for (l in that.fn.up) {
						that.fn.up[l]();
					}
					Tyre.search.up();
					Tyre.console.debug("scroll up");
				}
			}
		},
		fixedTop: function() {
			this.target = $(this.navbar);
			if (this.target.size() > 0) {
				//var heit = $(this.topbar).height();
				var that = this;
				$(window).on('scroll.window',
				function() {
					that.position();
				});
			}
		}
	};
	// ////////////////////////////////////////////////////
	// Log Console level: 0:debug, 1:info, 2:warn, 3:error
	// ////////////////////////////////////////////////////
	Tyre.console = {
		level: 1,
		pop: false,
		popheight: 0,
		// private
		log: function(msg) {
			if ($('#logpopcontent').size() == 0) {
				$(document.body).append("<div id='logpopcontent' class='popcontent'></div>");
			}
			var log = $("<div class='logpop'>" + msg + "</div>");
			$('#logpopcontent').append(log);
			log.animate({
				opacity: "show",
				top: this.popheight
			},
			"slow");
			setTimeout(function() {
				log.remove();
			},
			3000);
		},
		info: function(msg) {
			if (this.level <= 1) {
				if (this.pop) {
					this.log('[INFO] ' + msg);
				} else {
					console.info(' [INFO] ' + msg);
				}
			}
		},
		warn: function(msg) {
			if (this.level <= 2) {
				if (this.pop) {
					this.log('[WARN] ' + msg);
				} else {
					console.warn(' [WARN] ' + msg);
				}
			}
		},
		error: function(msg) {
			if (this.level <= 3) {
				if (this.pop) {
					this.log('[ERROR] ' + msg);
				} else {
					console.error('[ERROR] ' + msg);
				}
			}
		},
		debug: function(msg) {
			if (this.level <= 0) {
				if (this.pop) {
					this.log('[DEBUG] ' + msg);
				} else {
					console.log('[DEBUG] ' + msg);
				}
			}
		}
	};
	// ////////////////////////////////////////////////////
	// BackGround
	// ////////////////////////////////////////////////////
	Tyre.back = {
		backers: new Array(),
		show: function(options) {
			var key = 'root';
			if (options.target) {
				var j = options.target.substring(0, 1);
				if (j == '.') {
					key = 'class_' + options.target.substring(1);
				} else if (j == '#') {
					key = 'id_' + options.target.substring(1);
				}
			}
			var defaults = {
				clickhide: true
			};
			options = $.extend({},
			defaults, {},
			options);
			this.backers[key] = $('<div id="tyreback_' + key + '" class="modal-backdrop in"></div>');
			var bg = this.backers[key];
			if (options.target) {
				bg.attr('bgtarget', options.target);
			} else {
				bg.attr('bgtarget', 'root');
			}
			if (options.target) {
				var target = $(options.target);
				target.append(bg);
				bg.css('position', 'relative')
				.css('float', 'left');
				var top = bg.offset().top-target.offset().top;
				var left= bg.offset().left-target.offset().left;
				bg.css('width', target.innerWidth() + 'px')
				.css('height', target.innerHeight() + 'px')
				.css('margin-top', -top + 'px')
				.css('margin-left', -left + 'px')
				.css('z-index', options.z_index ? options.z_index: '999');
			} else {
				$(document.body).append(bg);
			}
			if (options.color) {
				bg.css('background-color', options.color);
				bg.attr('oldbgcolor', bg.css('background-color'));
			}
			if (options.clickhide) {
				var that = this;
				bg.click(function() {
					that.hide($(this).attr('bgtarget'));
				});
			}
		},
		hide: function(backerKey) {
			if (backerKey) {
				var j = backerKey.substring(0, 1);
				if (j == '.') {
					key = 'class_' + backerKey.substring(1);
				} else if (j == '#') {
					key = 'id_' + backerKey.substring(1);
				} else {
					key = 'root';
				}
			} else {
				key = 'root';
			}
			var bg = $('#tyreback_' + key);
			bg.remove();
			if (bg.attr('oldbgcolor')) {
				bg.css('background-color', bg.attr('oldbgcolor'));
			}
			this.backers[key] = null;
		}
	};
	// ////////////////////////////////////////////////////
	// Drag
	// ////////////////////////////////////////////////////
	Tyre.drag = {

		onpress: function(e) {
			this.target.css({
				"opacity": "0.9",
				"filter": "Alpha(Opacity=90)"
			});

			this.deltaX = e.clientX - this.target.offset().left + $(document).scrollLeft();
			this.deltaY = e.clientY - this.target.offset().top + $(document).scrollTop();
		},
		onblur: function() {
			this.target.css({
				"opacity": "1",
				"filter": "Alpha(Opacity=100)"
			});
		},
		onmove: function(e) {
			var left = (e.clientX - this.deltaX);
			var top = (e.clientY - this.deltaY);
			var l = 0;
			try{l=this.target.css('margin-left');if(l.indexOf("px")!=-1)l=parseInt(l.replace("px", ""), 10);else l=0;}catch(e){}
			var t = 0;
			try{t=this.target.css('margin-top');if(t.indexOf("px")!=-1)t=parseInt(t.replace("px", ""), 10);else t=0;}catch(e){}
			var w = $(window).width() - this.target.width() - l;
			var h = $(window).height() - this.target.height() - t;
			left=left-l;
			top=top-t;
			if (left > w) left = w;
			if (top > h) top = h;
			if (left + l < 0) left = -l;
			if (top + t < 0) top = -t;
			this.target.css({
				"left": left + "px",
				"top": top + "px"
			});
		},
		start: function(e, obj) {
			var trigger = $(e.target);
			var target = trigger.attr('drag-target');
			if (target) {
				this.target = $(target);
			} else {
				this.target = obj;
			}
			this.onpress(e);
			$(document).on("mousemove.drag", $.proxy(this.move, this));
			$(document).on("mouseup.drag", $.proxy(this.stop, this));
			e.preventDefault();
			Tyre.console.debug("target dom [" + this.target.attr('id') + "] start darg. on [mousemove.drag], [mouseup.drag]");

		},
		move: function(e) {
			this.onmove(e);
			e.preventDefault();
		},
		stop: function() {
			this.onblur();
			$(document).off("mousemove.drag");
			$(document).off("mouseup.drag");
			Tyre.console.debug("target dom [" + this.target.attr('id') + "] stop darg. off [mousemove.drag], [mouseup.drag]");
		}
	};
	// ////////////////////////////////////////////////////
})(window);

( function( $ ) {
    // for better compression with YUI compressor
    var FALSE = false,
    NULL = null;
    
    $.quickFlip = {
        wrappers : [],
        opts  : [],
        objs     : [],
        
        init : function( options, box ) {
        	
            options = options || {};
            
            options.closeSpeed = options.closeSpeed || 180;
            options.openSpeed  = options.openSpeed  || 120;
            
            options.ctaSelector = options.ctaSelector || '.quickFlipCta';
            
            options.refresh = options.refresh || FALSE;
            
            options.easing = options.easing || 'swing';
            
            options.noResize = options.noResize || FALSE;
            
            options.vertical = options.vertical || FALSE;
            
            var $box = typeof( box ) != 'undefined' ? $(box) : $('.quickFlip'),
            $kids = $box.children();
            
            // define $box css
            if ( $box.css('position') == 'static' ) $box.css('position', 'relative');
            
            // define this index
            var i = $.quickFlip.wrappers.length;
            
            // close all but first panel before calculating dimensions
            $kids.each(function(j) {
                var $this = $(this);
                
                // attach standard click handler
                if ( options.ctaSelector ) {
                    $this.find(options.ctaSelector).click(function(ev) {
                        ev.preventDefault();
                        $.quickFlip.flip(i);
                    });
                }

                if ( j ) $this.hide();
            });
            
            $.quickFlip.opts.push( options );
            
            $.quickFlip.objs.push({$box : $($box), $kids : $($kids)});
            
            $.quickFlip.build(i);
            
            
            
            // quickFlip set up again on window resize
            if ( !options.noResize ) {
                $(window).resize( function() {
                    for ( var i = 0; i < $.quickFlip.wrappers.length; i++ ) {
                        $.quickFlip.removeFlipDivs(i);
                        
                        $.quickFlip.build(i);
                    }
                });
            }
        },
        
        build : function(i, currPanel) {
            // get box width and height
            $.quickFlip.opts[i].panelWidth = $.quickFlip.opts[i].panelWidth || $.quickFlip.objs[i].$box.width();
            $.quickFlip.opts[i].panelHeight = $.quickFlip.opts[i].panelHeight || $.quickFlip.objs[i].$box.height();
            
             // init quickFlip, gathering info and building necessary objects
            var options = $.quickFlip.opts[i],
            
            thisFlip = {
                wrapper    : $.quickFlip.objs[i].$box,
                index      : i,
                half       : parseInt( (options.vertical ? options.panelHeight : options.panelWidth) / 2),
                panels     : [],
                flipDivs   : [],
                flipDivCols : [],
                currPanel   : currPanel || 0,
                options     : options
            };
            
            // define each panel
            $.quickFlip.objs[i].$kids.each(function(j) {
                var $thisPanel = $(this).css({
                    position : 'absolute',
                    top : 0,
                    left : 0,
                    margin : 0,
                    padding : 0,
                    width : options.panelWidth,
                    height : options.panelHeight
                });
                
                thisFlip.panels[j] = $thisPanel;
                
                // build flipDivs
                var $flipDivs = buildFlip( thisFlip, j ).hide().appendTo(thisFlip.wrapper);
                
                thisFlip.flipDivs[j] = $flipDivs;
                thisFlip.flipDivCols[j] = $flipDivs.children();
            });
            
            $.quickFlip.wrappers[i] = thisFlip;
            
            function buildFlip( x, y ) {
                // builds one column of the flip divs (left or right side)
            
                var $out = $('<div></div>'),
                
                flipCss = {
                    width : options.vertical ? options.panelWidth : x.half,
                    height : options.vertical ? x.half : options.panelHeight,
                    position : 'absolute',
                    overflow : 'hidden',
                    margin : 0,
                    padding : 0
                };
                
                function buildFlipCol(x, y) {
                    var $col = $('<div></div>'),
                    $inner = x.panels[y].clone().show();
                    
                    $col.css(flipCss);
                    
                    $col.html($inner);
                    
                    return $col;
                }
                
                if ( options.vertical ) flipCss.left = 0;
                else flipCss.top = 0;
                
                var $col1 = $(buildFlipCol(x, y)).appendTo( $out ),
                $col2 = $(buildFlipCol(x, y)).appendTo( $out );
                
                if (options.vertical) {
                    $col1.css('bottom', x.half);
                    
                    $col2.css('top',  x.half);
                    
                    $col2.children().css({
                        top : NULL,
                        bottom: 0
                    });
                }
                else {
                    $col1.css('right', x.half);
                    $col2.css('left', x.half);
                    
                    $col2.children().css({
                        right : 0,
                        left : 'auto'
                    });
                }
                
                return $out;
            }
        },
        
        // function flip ( i is quickflip index, j is index of currently open panel)
        
        flip : function( i, nextPanel, repeater, options) {
            function combineOpts ( opts1, opts2 ) {
                opts1 = opts1 || {};
                opts2 = opts2 || {};
                
                for ( opt in opts1 ) {
                    opts2[opt] = opts1[opt];
                }
                
                return opts2;
            }
        
            if ( typeof i != 'number' || typeof $.quickFlip.wrappers[i] == 'undefined' ) return;
            
            var x = $.quickFlip.wrappers[i],
        
            j = x.currPanel,
            k = ( typeof(nextPanel) != 'undefined' && nextPanel != NULL ) ? nextPanel : ( x.panels.length > j + 1 ) ? j + 1 : 0;
            x.currPanel = k,
            
            repeater = ( typeof(repeater) != 'undefined' && repeater != NULL ) ? repeater : 1;
            
            options = combineOpts( options, $.quickFlip.opts[i] );
    
            x.panels[j].hide();
            
            // if refresh set, remove flipDivs and rebuild
            if ( options.refresh ) {
                $.quickFlip.removeFlipDivs(i);
                $.quickFlip.build(i, k);
                
                x = $.quickFlip.wrappers[i];
            }
            
            x.flipDivs[j].show();
            
            // these are due to multiple animations needing a callback
            var panelFlipCount1 = 0,
            panelFlipCount2 = 0,
            closeCss = options.vertical ? { height : 0 } : { width : 0 },
            openCss = options.vertical ? { height : x.half } : { width : x.half };
            
            x.flipDivCols[j].animate( closeCss, options.closeSpeed, options.easing, function() {
                if ( !panelFlipCount1 ) {
                    panelFlipCount1++;
                }
                else {
                    x.flipDivs[k].show();
                    
                    x.flipDivCols[k].css(closeCss);
                    
                    x.flipDivCols[k].animate(openCss, options.openSpeed, options.easing, function() {
                        if ( !panelFlipCount2 ) {
                            panelFlipCount2++;
                        }
                        else {
                            
                            x.flipDivs[k].hide();
                            
                            x.panels[k].show();
                            
                            // handle any looping of the animation
                            switch( repeater ) {
                                case 0:
                                case -1:
                                    $.quickFlip.flip( i, NULL, -1);
                                    break;
                                
                                //stop if is last flip, and attach events for msie
                                case 1: 
                                    break;
                                    
                                default:
                                    $.quickFlip.flip( i, NULL, repeater - 1);
                                    break;
                            }
                        }
                    });
                }
            });
            
        },
        
        removeFlipDivs : function(i) {
            for ( var j = 0; j < $.quickFlip.wrappers[i].flipDivs.length; j++ ) $.quickFlip.wrappers[i].flipDivs[j].remove();
        }
    };

    $.fn.quickFlip = function( options ) {
        this.each( function() {
            new $.quickFlip.init( options, this );
        });
        
        return this;
    };
    
    $.fn.whichQuickFlip = function() {
        function compare(obj1, obj2) {
            if (!obj1 || !obj2 || !obj1.length || !obj2.length || obj1.length != obj2.length) return FALSE;
            
            for ( var i = 0; i < obj1.length; i++ ) {
                if (obj1[i]!==obj2[i]) return FALSE;
            }
            return true;
        }
        
        var out = NULL;
        
        for ( var i=0; i < $.quickFlip.wrappers.length; i++ ) {
            if ( compare(this, $( $.quickFlip.wrappers[i].wrapper)) ) out = i;
        }
        
        return out;
    };
    
    $.fn.quickFlipper = function( options, nextPanel, repeater ) {
        this.each( function() {
            var $this = $(this),
            thisIndex = $this.whichQuickFlip();
            
            // if doesnt exist, set it up
            if ( thisIndex == NULL ) {
                $this.quickFlip( options );
                
                thisIndex = $this.whichQuickFlip();
            }
            
            $.quickFlip.flip( thisIndex, nextPanel, repeater, options );
        });
    };
    
})( jQuery );

// Menu/////////////////////////////////////////////////////////////////////////////////////
!
function($) {

	"use strict";

	var Menu = function(element, options) {
		this.$element = $(element);
		this.options = $.extend({},
		$.fn.menu.defaults, this.$element.data(), options);
		this.init();
		// if(this.options.open)
		this.show();
	};

	Menu.prototype = {

		constructor: Menu,
		name: '__w_menu',
		nameSub: '__w_submenu',
		onsub: 0,
		index: 1,
		hover: 0,
		init: function() {
			// root menu
			if ($('#' + this.name).size() < 1) {
				$(document.body).append('<div id=' + this.name + ' index=0 ><div style="margin: 0pt;"><div class="menu_base"><div class="menu_bd bd"><div class="txtflow menu_inner context"></div><div class="txtflow menu_inner foot"></div></div></div></div></div>');
				Tyre.console.debug("menu dom [" + this.name + "] created.");
			}
			this.root = $('#' + this.name);
			// var binded = this.$element.attr('aria-bind-menu');
			// if(!binded) {
			// this.$element.attr('aria-bind-menu','true');
			// this.$element.bind(this.options.trigger, $.proxy(this.show,
			// this))
			// }

		},
		resize: function() {
			if (!this.isClosed) {
				this.position();
				$('.' + this.nameSub).css('display', 'none');
				Tyre.console.debug("menu [" + this.name + "] resised .");
			}
		},
		hide: function(e) {
			if (e) {
				if ($(e.target).closest('.menu_item').length > 0 || $(e.target).closest(this.$element).length > 0 || $(e.target)[0] == this.$element[0]) {
					return
				}
			}

			$(window).off('resize.menu-window-resize');
			$(document).off('click.menu-document-click');
			this.root.css('display', 'none');
			this.root.attr('class', '');
			$('.' + this.nameSub).css('display', 'none');
			this.isClosed = true;

			Tyre.console.debug("menu [" + this.name + "] hide . off [resize.menu-window-resize],[click.menu-document-click]");
		},
		subHover: function(obj, j) {
			this.onsub = 1;
			this.hover = parseInt(obj.attr('index'), 10);
		},
		subOut: function(obj, timeout) {
			this.onsub = 0;
			this.closeSub(timeout ? timeout: 500, obj);
		},
		close: function() {
			var hover = this.hover;
			if (this.onsub == 0) {
				hover = -1;
			}
			$('.' + this.nameSub).each(function(e, i) {
				if (parseInt($(this).attr('index')) > hover + 1) {
					$(this).css('display', 'none');
				}
			});
		},
		closeSub: function(timeout, obj) {
			if (timeout && timeout > 0) {
				setTimeout($.proxy(this.close, this), timeout);
			} else {
				this.close();
			}

		},
		position: function() {
			var element = this.$element;
			this.root.css('display', 'none');
			var target = this.options.type == 'select' ? element.parent() : element;
			var offset = target.offset();

			var y = offset.top + target.innerHeight();
			var x = offset.left + (this.options.position == 'left' ? 0 : target.innerWidth());

			var r = this.root.width();

			var h = $(document).height();
			var eh = $('#' + this.name).innerHeight();
			if (y + eh + 2 >= h) {
				y = y - eh;
			}
			
			this.root.css('top', y + 'px');
			this.root.css('left', ((x + r) > document.body.scrollWidth ? x - r + target.innerWidth() : x) + 'px');
			this.root.css('display', 'block');
		},

		show: function() {

			this.hide();
			this.isClosed = false;
			this.root.attr('class', 'wshadow ' + this.options.clazz);
			// var top = document.documentElement.scrollTop;
			// if (top == 0)
			// top = document.body.scrollTop;
			this.create();

			this.position();

			this.root.css('display', 'block');

			var that = this;

			$(document).on('click.menu-document-click',
			function(e) {
				that.hide(e);
			});

			$(window).on('resize.menu-window-resize', $.proxy(this.resize, this));

			Tyre.console.debug("menu [" + this.name + "] show . on [resize.menu-window-resize],[click.menu-document-click]");
		},
		change: function(o, i) {
			if (i == 0) {
				o.find('s').removeClass('icon-white');
			} else {
				o.find('s').addClass('icon-white');
			}
		},
		build: function(option, i, index) {
			var that = this;
			var menu = '';
			var ic = option[i].icon ? option[i].icon: "&nbsp;";
			if (option[i].line) {
				menu = $('<div class=menu_line></div>');
			} else {
				if (option[i].sub) {
					menu = $('<div id=":b' + i + ':' + index + '" class="menu_name" i=' + i + ' index=' + index + ' ><div class=menu_item ><table width="100%"><tr><td class="tdleft"><div class="menu_item_t">' + ic + '</div>' + option[i].name + '</td><td><s class="caret"></s></td><tr></table></div></div>');
					menu.bind('mouseenter',
					function() {
						that.subHover($(this));
						that.createSub($(this), option, $(this).attr('index'));
					});
					menu.bind('mouseleave',
					function() {
						that.subOut($(this));
					});
				} else {
					menu = $('<div class="menu_name" i=' + i + ' index=' + (index - 1) + ' ><div class=menu_item ><div class="menu_item_t">' + ic + '</div>' + option[i].name + '</div></div>');
					if (option[i].click) {
						menu.click(function(e) {
							var data = option[$(this).attr('i')];
							if (typeof(data.autoClose) == "undefined" || data.autoClose == true) {
								that.hide();
							}
							option[$(this).attr('i')].click($(this), that);
							return false;
						});
					} else {
						menu.click(function(e) {
							var data = option[$(this).attr('i')];
							if (typeof(data.autoClose) == "undefined" || data.autoClose == true) {
								that.hide();
							}
							return false;
						});
					}
					menu.bind('mouseenter',
					function() {
						that.subHover($(this));
					});
					menu.bind('mouseleave',
					function() {
						that.subOut($(this));
					});
				}
			}
			return menu;
		},
		create: function() {
			var that = this;
			var target = this.root.find('.context');
			target.html('');
			this.root.find('.foot').html('');
			var len = this.options.menus.length;
			if (len > 0) {
				for (var i = 0; i < len; i++) {
					target.append(this.build(this.options.menus, i, this.root.attr('index')));
				}
			}
			if (!this.options.foot) {
				if (this.options.foot == undefined) {
					var close = $('<div class=menu_name><div class=menu_line></div><div class="menu_item" ><div class="menu_item_t">&nbsp;</div>取消</div></div>');
					close.click(function() {
						that.hide();
					});
					this.root.find('.foot').append(close);
				}
			} else if (this.options.foot && this.options.foot != null) {
				var close = $('<div class=menu_name><div class=menu_line></div><div class="menu_item" ><div class="menu_item_t">&nbsp;</div>' + this.options.foot.title + '</div></div>');
				close.click(function() {
					that.options.foot.onClick($(this), that);
					that.hide();
				});
				this.root.find('.foot').append(close);
			}
			Tyre.console.debug("menu [" + this.name + "] create root menu . len : " + len);
		},
		createSub: function(obj, parent, index) {
			var name = this.nameSub + index;
			var $el = $('#' + name);
			if ($el.size() == 0) {
				$el = $('<div id=' + name + ' index=' + this.index + ' class="wshadow ' + this.nameSub + '"><div style="margin: 0pt;"><div class="menu_base"><div class="menu_bd bd"><div class="txtflow menu_innersub"></div></div></div></div></div>');
				$(document.body).append($el);
				this.index++;
			}

			var i = obj.attr('i');
			var option = parent[i].sub;

			$el.find('.menu_innersub').html('');
			var len = option.length;

			if (len > 0) {
				for (i = 0; i < len; i++) {
					var menu = this.build(option, i, $el.attr('index'));
					$el.find('.menu_innersub').append(menu);
				}
			}

			$el.css('display', 'block');

			var x = obj.offset().left;
			var y = obj.offset().top;

			var r = $el.width();

			$('#' + name).css('top', y + 'px');
			$('#' + name).css('left', ((x + r * 2) > document.body.scrollWidth ? x - r + 5 : x + r - 8) + 'px');
			Tyre.console.debug("menu [" + this.name + "] create sub menu . len : " + len + ", index : " + this.index + ", name : " + name);
		}
	};

	/* PLUG IN********************** */

	var old = $.fn.menu;

	$.fn.menu = function(option) {
		return this.each(function() {
			var $this = $(this),
			data = $this.data('menu'),
			options = typeof option == 'object' && option;
			if (!data || options.perNew) $this.data('menu', (data = new Menu(this, options)));
			else data.show();
			if (typeof option == 'string') data[option]();
		});
	};

	$.fn.menu.Constructor = Menu;

	$.fn.menu.defaults = {
		// trigger : 'click',
		// foot : '',
		position: 'right',
		clazz: '',
		menus: [],
		open: false,
		perNew: false
	};

	$.fn.menu.noConflict = function() {
		$.fn.menu = old;
		return this;
	};

} (window.jQuery);

// NOTICE/////////////////////////////////////////////////////////////////////////////////////
!
function($) {

	"use strict";

	var Notice = function(element, options) {
		this.$element = $(element);
		this.options = $.extend({},
		$.fn.notice.defaults, this.$element.data(), options);
		this.init();
	};

	Notice.prototype = {

		constructor: Notice,
		name: '__w_notice',
		max: 'wnoticeopen',
		init: function() {

			if ($('#' + this.name).size() < 1) {
				$(document.body).append('<div id=' + this.name + ' class="wnotice wnoticeshadow" style="display:none">' + '<div class="nH Hy" style="height:34px;">' + '<div class="l n">' + '<div class="k" style="padding: 3px 0px 7px; margin: 0px 3px 0px 0px;">' + '<div class="nH aBp">' + '<table cellpadding="0" class="cf Ht drag-trigger">' + '<tr>' + '<td  style="width:70%">' + '<div class="Hp"><table><tr><td></td><td> <span class="Hti"></span></td></tr></table></div>' + //<i class=" icon-comment icon-white"></i>// <i
				// class="
				// icon-info-sign
				// icon-white"></i>
				'</td>' + '<td class="Hm">' + '<i class="Hmini Hk" title="最大化"></i>' + '<i class="Hexpand Hq aUG" title="全屏模式"></i>' + '<i class="Hclose Ha" title="关闭"></i>' + '</td>' + '</tr>' + '</table>' + '</div>' + '</div>' + '</div>' + '</div>' + '<div class="aac">' + '<div class="aaz">' + '</div>' + '</div>' + '</div>');

				$('#' + this.name + ' .Hy').dblclick($.proxy(this.mini, this));
				$('#' + this.name + ' .Hm').find('.Hmini').click($.proxy(this.mini, this));
				$('#' + this.name + ' .Hm').find('.Hexpand').click($.proxy(this.expand, this));
				$('#' + this.name + ' .Hm').find('.Hclose').click($.proxy(this.close, this));
				$('#' + this.name + ' .Hp').find('.Hti').click($.proxy(this.expand, this));
			}

			// if(this.options.tigger && this.options.tigger != null) {
			// this.$element.bind(this.options.tigger, $.proxy(this.show, this));
			// } else {
			this.show();
			// }
		},
		show: function() {
			$('#' + this.name).removeAttr('style');
			$('#' + this.name).hide();
			$('#' + this.name + ' .Hti').html(this.options.title);
			$('#' + this.name + ' .aaz').html(this.options.html);
			$('#' + this.name + ' .aac').hide();

			$('#' + this.name).removeClass(this.max);
			$('#' + this.name + ' .Hq').addClass('aUG').attr('title', '全屏模式');
			$('#' + this.name + ' .Hl').addClass('Hk').removeClass('Hl').attr('title', '最大化');

			if (this.options.type == 'mini') {
				this.mini(1);
				$('#' + this.name).show();
			} else if (this.options.type == 'expand') {
				this.expand(1);
				$('#' + this.name).show();
			} else {
				$('#' + this.name).slideDown("1500");
			}

			Tyre.console.debug("show notice with options [type:" + this.options.type + "].");

		},
		close: function() {
			this.offdrag();
			$('#' + this.name).hide();
		},
		offdrag: function() {
			$('#' + this.name).removeAttr('style');
			var ht = $('#' + this.name).find('.drag-trigger');
			ht.css('cursor', 'pointer');
			ht.off('mousedown.dragnotice');
			Tyre.console.debug("notice offdrag event, target dom [" + this.$element.attr('id') + "] off [mousedown.dragnotice] darg.");
		},
		startdrag: function() {
			var that = this;
			var ht = $('#' + this.name).find('.drag-trigger');
			ht.css('cursor', 'move');
			ht.on('mousedown.dragnotice',
			function(e) {
				if (Tyre.drag) {
					Tyre.drag.start(e, $('#' + that.name));
				}
			});
			Tyre.console.debug("notice startdrag event, target dom [" + this.$element.attr('id') + "] on [mousedown.dragnotice] darg.");
		},
		hide: function() {
			this.close();
		},
		mini: function(i) {
			if ($('#' + this.name + ' .Hl').size() > 0) {
				$('#' + this.name).removeClass(this.max);
				$('#' + this.name + ' .Hq').addClass('aUG').attr('title', '全屏模式');
				$('#' + this.name + ' .Hl').addClass('Hk').removeClass('Hl').attr('title', '最大化');
				$('#' + this.name + ' .aac').hide();
				$('#' + this.name).css('width', '220px');
				this.offdrag();
			} else {
				$('#' + this.name + ' .Hk').addClass('Hl').removeClass('Hk').attr('title', '最小化');
				$('#' + this.name + ' .aac').show();
				$('#' + this.name).attr('oldwidth', $('#' + this.name).width());
				$('#' + this.name).css('width', '480px');
			}
		},
		expand: function(i) {
			// open
			if ($('#' + this.name + ' .aUG').size() > 0) {
				$('#' + this.name).addClass(this.max);
				$('#' + this.name + ' .Hq').removeClass('aUG').attr('title', '退出全屏模式');
				$('#' + this.name + ' .Hk').addClass('Hl').removeClass('Hk').attr('title', '最小化');
				$('#' + this.name + ' .aac').show();
				$('#' + this.name).css('width', '70%');
				// drag
				this.startdrag();
			}
			// close
			else {
				$('#' + this.name).removeClass(this.max);
				$('#' + this.name + ' .Hq').addClass('aUG').attr('title', '全屏模式');
				$('#' + this.name + ' .Hl').addClass('Hk').removeClass('Hl').attr('title', '最大化');
				$('#' + this.name + ' .aac').hide();
				$('#' + this.name).css('width', '220px');
				this.offdrag();
			}
		}

	};

	/* PLUG IN********************** */

	var old = $.fn.notice;

	$.fn.notice = function(option) {
		return this.each(function() {
			var $this = $(this),
			data = $this.data('notice'),
			options = typeof option == 'object' && option;
			if (!data) $this.data('notice', (data = new Notice(this, options)));
			else data.show();
			if (typeof option == 'string') data[option]();
		});
	};

	$.fn.notice.Constructor = Notice;

	$.fn.notice.defaults = {
		title: '个人消息',
		button: 'mini,expand',
		tigger: null,
		html: '',
		type: 'hide'
	};

	$.fn.notice.noConflict = function() {
		$.fn.notice = old;
		return this;
	};

} (window.jQuery);

// SelectMenu/////////////////////////////////////////////////////////////////////////////////////
!
function($) {

	"use strict";

	if (!$.fn.menu) {
		window.alert('需要menu.js');
		return;
	}

	var SelectMenu = function(element, options) {
		this.$element = $(element);
		this.options = $.extend({},
		$.fn.selectmenu.defaults, this.$element.data(), options);
		this.show();
	};

	SelectMenu.prototype = {

		constructor: SelectMenu,
		show: function() {
			var data = '';
			if (this.options.data != null) {
				data = this.options.data;
			} else {
				data = this.$element.attr('data');
			}

			if (data == '' || data == '[[]]') {
				data = '[]';
			}
			data = eval(data);
			var option = [];
			for (var i = 0; i < data.length; i++) {
				option[i] = {
					icon: '<span class="I" ' + (this.options.border == false ? ' style="border-color:transparent;" ': '') + '>' + (data[i][2] ? "<i class=\"selected\"></i>": "") + '</span>',
					name: '<span class="mV" ' + (data[i][3] ? 'check-all=true': '') + ' ' + (data[i][2] ? "check=true": "") + ' data="' + data[i][0] + '">' + data[i][1] + '</span>',
					autoClose: false,
					click: function(e, root) {
						try {
							var c = e.find('.mV').attr('check');
							var a = e.find('.mV').attr('check-all');
							if (a) {
								if (typeof(c) == "undefined" || c == 'false') {
									root.root.find('i').remove();
									root.root.find('.mV').attr('check', 'true');
									root.root.find('.I').append('<i class="selected"></i>');
								} else {
									root.root.find('.mV').attr('check', 'false');
									root.root.find('i').remove();
								}
							} else {

								if (typeof(c) == "undefined" || c == 'false') {
									e.find('.mV').attr('check', 'true');
									e.find('.I').append('<i class="selected"></i>'); // .css('padding-left','1px').css('padding-right','6px')
								} else {
									e.find('.mV').attr('check', 'false');
									e.find('i').remove();
								}
							}
						} catch(e) {
							Tyre.console.error(e);
						}
					}
				};
			}

			var that = this;
			if (data.length == 0) {
				this.$element.menu({
					// trigger:'click',
					clazz: (this.options.fixed) ? '': 'wselectmenu',
					foot: {
						title: '没有可供选择的数据项。',
						onClick: function(e, root) {
							Tyre.alert({
								text: '没有可供选择的数据项。'
							});
						}
					},
					position: 'left',
					type: 'select',
					menus: option,
					perNew: true
				});
			} else {
				this.$element.menu({
					// trigger:'click',
					clazz: (this.options.fixed) ? '': 'wselectmenu',
					foot: {
						title: '应用',
						onClick: function(e, root) {

							var span = root.root.find('.mV');
							var values = [];
							var i = 0;
							span.each(function() {
								var t = $(this);
								var c = t.attr('check');
								if (typeof(c) != "undefined" && c == 'true') {
									values[i++] = {
										lebal: t.html(),
										value: t.attr('data')
									};
								}
							});
							that.options.onClick(values, e, root, that);
						}
					},
					position: 'left',
					type: 'select',
					menus: option,
					perNew: true
				});
			}
		}

	};
	/* PLUG IN********************** */

	var old = $.fn.selectmenu;

	$.fn.selectmenu = function(option) {
		return this.each(function() {
			var $this = $(this),
			data = $this.data('selectmenu'),
			options = typeof option == 'object' && option;
			if (!data || options.perNew) $this.data('selectmenu', (data = new SelectMenu(this, options)));
			else data.show();
			if (typeof option == 'string') data[option]();
		});
	};

	$.fn.selectmenu.Constructor = SelectMenu;

	$.fn.selectmenu.defaults = {
		// trigger : 'click',
		close: true,
		data: null,
		fixed: false,
		border: true,
		perNew: true
	};

	$.fn.selectmenu.noConflict = function() {
		$.fn.selectmenu = old;
		return this;
	};

} (window.jQuery);

// Indicator////////////////////////////////////////
!
function($) {

	"use strict";

	var Indicator = function(element, options) {
		this.$element = $(element);
		this.options = $.extend({},
		$.fn.indicator.defaults, this.$element.data(), options);
		this.init();
		// this.show()
	};

	Indicator.prototype = {

		constructor: Indicator,
		name: '__w_indicator',
		timeoutKey: undefined,
		timeoutHover: 0,
		init: function() {
			// root
			if (!this.root) {

				this.root = $("<div id=" + this.name + " class='popcontent " + (this.options.position == 'left' ? 'leftcontent': '') + ' ' + this.options.clazz + "' ></div>");
				$(document.body).append(this.root);
				var that = this;
				// bind event
				this.$element.on('mouseenter',
				function() {
					if (that.timeoutHover == 0) {
						that.timeoutHover = 1;
						that.show();
					}
				});
				this.$element.on('mouseleave',
				function() {
					that.timeoutHover = 0;
					if (that.timeoutKey) clearTimeout(that.timeoutKey);
					that.timeoutKey = setTimeout(function() {
						that.hide();
					},
					400);
				});
				this.root.on('mouseenter',
				function() {
					that.timeoutHover = 1;
				});
				this.root.on('mouseleave',
				function() {
					that.timeoutHover = 0;
					if (that.timeoutKey) clearTimeout(that.timeoutKey);
					that.timeoutKey = setTimeout(function() {
						that.hide();
					},
					400);
				});
				Tyre.console.debug("indicator dom [" + this.name + "] created.");
				this.root.html(this.options.html);
			}
		},
		show: function() {

			var top = this.$element.parent().offset().top - $(window).scrollTop() + this.$element.parent().height() + "px";
			this.root.css('top', top);
			this.root.animate({
				left: '0px'
			},
			230);
			var that = this;
			$(window).on('scroll.indicator',
			function() {
				that.root.css('top', that.$element.parent().offset().top - $(window).scrollTop() + that.$element.parent().height() + "px");
			});

		},
		hide: function() {
			if (this.timeoutHover == 0) {
				this.root.animate({
					left: '-260px'
				},
				230);
				$(window).off('scroll.indicator');
			}
		}

	};
	/* PLUG IN********************** */

	var old = $.fn.indicator;

	$.fn.indicator = function(option) {
		return this.each(function() {
			var $this = $(this),
			data = $this.data('indicator'),
			options = typeof option == 'object' && option;
			if (!data) $this.data('indicator', (data = new Indicator(this, options)));
			else data.show();
			if (typeof option == 'string') data[option]();
		});
	};

	$.fn.indicator.Constructor = Indicator;

	$.fn.indicator.defaults = {
		// trigger : 'click',
		// close : true,
		// data:null
		clazz: '',
		position: 'left',
		html: ''
	};

	$.fn.indicator.noConflict = function() {
		$.fn.indicator = old;
		return this;
	};

} (window.jQuery);

////////////////////
!
function(name, context, definition) {
	if (typeof module !== 'undefined') module.exports = definition(name, context);
	else if (typeof define === 'function' && typeof define.amd === 'object') define(definition);
	else context[name] = definition(name, context);
} ('humane', this.Tyre,
function(name, context) {
	var win = window;
	var doc = document;

	var ENV = {
		on: function(el, type, cb) {
			'addEventListener' in win ? el.addEventListener(type, cb, false) : el.attachEvent('on' + type, cb);
		},
		off: function(el, type, cb) {
			'removeEventListener' in win ? el.removeEventListener(type, cb, false) : el.detachEvent('on' + type, cb);
		},
		bind: function(fn, ctx) {
			return function() {
				fn.apply(ctx, arguments);
			};
		},
		isArray: Array.isArray ||
		function(obj) {
			return Object.prototype.toString.call(obj) === '[object Array]';
		},
		config: function(preferred, fallback) {
			return preferred != null ? preferred: fallback;
		},
		transSupport: false,
		useFilter: /msie [678]/i.test(navigator.userAgent),
		// sniff, sniff
		_checkTransition: function() {
			var el = doc.createElement('div');
			var vendors = {
				webkit: 'webkit',
				Moz: '',
				O: 'o',
				ms: 'MS'
			};

			for (var vendor in vendors) if (vendor + 'Transition' in el.style) {
				this.vendorPrefix = vendors[vendor];
				this.transSupport = true;
			}
		}
	};
	ENV._checkTransition();

	var Humane = function(o) {
		o || (o = {});
		this.queue = [];
		this.baseCls = o.baseCls || 'humane';
		this.addnCls = o.addnCls || '';
		this.timeout = 'timeout' in o ? o.timeout: 2500;
		this.waitForMove = o.waitForMove || false;
		this.clickToClose = o.clickToClose || false;
		this.timeoutAfterMove = o.timeoutAfterMove || false;
		this.container = o.container;

		try {
			this._setupEl();
		} // attempt to setup elements
		catch(e) {
			ENV.on(win, 'load', ENV.bind(this._setupEl, this)); // dom wasn't ready, wait till ready
		}
	};

	Humane.prototype = {
		constructor: Humane,
		_setupEl: function() {
			var el = doc.createElement('div');
			el.style.display = 'none';
			if (!this.container) {
				if (doc.body) this.container = doc.body;
				else throw 'document.body is null';
			}
			this.container.appendChild(el);
			this.el = el;
			this.removeEvent = ENV.bind(function() {
				if (!this.timeoutAfterMove) {
					this.remove();
				} else {
					setTimeout(ENV.bind(this.remove, this), this.timeout);
				}
			},
			this);
			this.transEvent = ENV.bind(this._afterAnimation, this);
			this._run();
		},
		_afterTimeout: function() {
			if (!ENV.config(this.currentMsg.waitForMove, this.waitForMove)) {
				if(this.el.getAttribute('over') == 'true') {
					ENV.on(this.el, 'mouseout', function() {
						this.remove();
					});
				} else {
					this.remove();
				}
			}
			else if (!this.removeEventsSet) {
				ENV.on(doc.body, 'mousemove', this.removeEvent);
				ENV.on(doc.body, 'click', this.removeEvent);
				ENV.on(doc.body, 'keypress', this.removeEvent);
				ENV.on(doc.body, 'touchstart', this.removeEvent);
				this.removeEventsSet = true;
			}
		},
		_run: function() {
			if (this._animating || !this.queue.length || !this.el) return

			this._animating = true;
			if (this.currentTimer) {
				clearTimeout(this.currentTimer);
				this.currentTimer = null;
			}

			var msg = this.queue.shift();
			var clickToClose = ENV.config(msg.clickToClose, this.clickToClose);

			if (clickToClose) {
				ENV.on(this.el, 'click', this.removeEvent);
				ENV.on(this.el, 'touchstart', this.removeEvent);
			}
			
			// add
			var el = this.el;
			ENV.on(this.el, 'mouseover', function() {
				el.setAttribute("over","true");
			});
			ENV.on(this.el, 'mouseout', function() {
				el.removeAttribute('over');
			});

			var timeout = ENV.config(msg.timeout, this.timeout);

			if (timeout > 0) this.currentTimer = setTimeout(ENV.bind(this._afterTimeout, this), timeout);

			if (ENV.isArray(msg.html)) msg.html = '<ul><li>' + msg.html.join('<li>') + '</ul>';

			this.el.innerHTML = msg.html;
			this.currentMsg = msg;
			this.el.className = this.baseCls;
			if (ENV.transSupport) {
				this.el.style.display = 'block';
				setTimeout(ENV.bind(this._showMsg, this), 50);
			} else {
				this._showMsg();
			}

		},
		_setOpacity: function(opacity) {
			if (ENV.useFilter) {
				try {
					this.el.filters.item('DXImageTransform.Microsoft.Alpha').Opacity = opacity * 100;
				} catch(err) {
					try {
						// 兼容IE8
						this.el.filters.item('Alpha').Opacity = opacity * 100;
					} catch(e) {}
				}
			} else {
				this.el.style.opacity = String(opacity);
			}
		},
		_showMsg: function() {
			var addnCls = ENV.config(this.currentMsg.addnCls, this.addnCls);
			if (ENV.transSupport) {
				this.el.className = this.baseCls + ' ' + addnCls + ' ' + this.baseCls + '-animate';
			} else {
				var opacity = 0;
				this.el.className = this.baseCls + ' ' + addnCls + ' ' + this.baseCls + '-js-animate';
				this._setOpacity(0); // reset value so hover states work
				this.el.style.display = 'block';
				var self = this;
				var interval = null;
				interval = setInterval(function() {
					if (opacity < 1) {
						opacity += 0.1;
						if (opacity > 1) opacity = 1;
						self._setOpacity(opacity);
					} else clearInterval(interval);
				},
				30);
			}
		},
		_hideMsg: function() {
			var addnCls = ENV.config(this.currentMsg.addnCls, this.addnCls);
			if (ENV.transSupport) {
				this.el.className = this.baseCls + ' ' + addnCls;
				ENV.on(this.el, ENV.vendorPrefix ? ENV.vendorPrefix + 'TransitionEnd': 'transitionend', this.transEvent);
			} else {
				var opacity = 1;
				var self = this;
				var interval = null;
				interval = setInterval(function() {
					if (opacity > 0) {
						opacity -= 0.1;
						if (opacity < 0) opacity = 0;
						self._setOpacity(opacity);
					} else {
						self.el.className = self.baseCls + ' ' + addnCls;
						clearInterval(interval);
						self._afterAnimation();
					}
				},
				30);
			}
		},
		_afterAnimation: function() {
			if (ENV.transSupport) ENV.off(this.el, ENV.vendorPrefix ? ENV.vendorPrefix + 'TransitionEnd': 'transitionend', this.transEvent);

			if (this.currentMsg.cb) this.currentMsg.cb();
			this.el.style.display = 'none';

			this._animating = false;
			this._run();

			document.body.removeChild(this.el);
		},
		remove: function(e) {
			var cb = typeof e == 'function' ? e: null;

			ENV.off(doc.body, 'mousemove', this.removeEvent);
			ENV.off(doc.body, 'click', this.removeEvent);
			ENV.off(doc.body, 'keypress', this.removeEvent);
			ENV.off(doc.body, 'touchstart', this.removeEvent);
			ENV.off(this.el, 'click', this.removeEvent);
			ENV.off(this.el, 'touchstart', this.removeEvent);
			//add
			ENV.off(this.el, 'mouseover', this.removeEvent);
			ENV.off(this.el, 'mouseout', this.removeEvent);
			
			this.removeEventsSet = false;

			if (cb && this.currentMsg) this.currentMsg.cb = cb;
			if (this._animating) this._hideMsg();
			else if (cb) cb();
		},
		log: function(html, o, cb, defaults) {
			var msg = {};
			if (defaults) for (var opt in defaults) msg[opt] = defaults[opt];

			if (typeof o == 'function') cb = o;
			else if (o) for (var opt in o) msg[opt] = o[opt];

			msg.html = html;
			if (cb) msg.cb = cb;
			this.queue.push(msg);
			this._run();
			return this;
		},
		spawn: function(defaults) {
			var self = this;
			return function(html, o, cb) {
				self.log.call(self, html, o, cb, defaults);
				return self;
			};
		},
		create: function(o) {
			return new Humane(o);
		}
	};
	return new Humane();
});